package com.hsq.androidproject.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Toast;

import com.example.lenovo.androidproject3.R;
import com.hsq.androidproject.entity.rtvdetails;
import com.hsq.androidproject.ui.IjkFullscreenActivity;

import java.util.List;

/**
 * Created by Administrator on 2017/3/18.
 */

public class MyrtvdetailsAdapter extends BaseAdapter {//rtv的集数统计和调播放页面

    private List<rtvdetails.PlayItemsBean> mData;
    private Context context;

    public MyrtvdetailsAdapter(List<rtvdetails.PlayItemsBean> mData, Context context) {
        this.mData = mData;
        this.context = context;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final MyrtvdetailsAdapter.ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.rtvitems, parent, false);
            viewHolder = new MyrtvdetailsAdapter.ViewHolder();
            viewHolder.btn_juji = (Button) convertView.findViewById(R.id.btn_juji);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (MyrtvdetailsAdapter.ViewHolder) convertView.getTag();
        }
        final rtvdetails.PlayItemsBean itemsBean = mData.get(position);
        int serialNo = itemsBean.getSerialNo();
        viewHolder.btn_juji.setText(serialNo + "");
        viewHolder.btn_juji.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String path = "http://api.hanju.koudaibaobao.com/api/series/itemRefV3?pid=" + itemsBean.getPid();
                Toast.makeText(context, "观看第" + viewHolder.btn_juji.getText().toString() + "集", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(context, IjkFullscreenActivity.class);
                intent.putExtra("path", "http://www.tudou.com/programs/view/7v5RI4jYnh0/?resourceId=24733090_06_02_99");
                context.startActivity(intent);
            }
        });
        return convertView;
    }

    class ViewHolder {
        public Button btn_juji;
    }
}
